﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using LogWatcher.Common;
using Microsoft.Win32;

namespace LogWatcherX
{
    /// <summary>
    /// Interaktionslogik für LoadFileWindow.xaml
    /// </summary>
    public partial class LoadFileWindow : Window
    {
        public static String ShowLoadFileDialog()
        {
            LoadFileWindow win = new LoadFileWindow();
            if (win.ShowDialog().GetValueOrDefault(false))
            {
                return win.cmbFile.Text;
            }

            return null;
        }

        private LoadFileWindow()
        {
            InitializeComponent();
            foreach (string file in HistoryFileManager.LoadHistoryFileList())
            {
                cmbFile.Items.Add(file);
            }
        }

        private void btnClear_Click(object sender, RoutedEventArgs e)
        {
            HistoryFileManager.ClearHistory();
            cmbFile.Items.Clear();
        }

        private void btnChoice_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "Log-Files|*.log|Text-Files|*.txt|All Files|*.*";
            openFileDialog.DefaultExt = "log|txt|";
            openFileDialog.FilterIndex = 3;

            if (openFileDialog.ShowDialog().GetValueOrDefault(false))
            {
                cmbFile.Text = openFileDialog.FileName;
                btnOk.IsEnabled = true;
            }
        }

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = true;
            Close();
        }
    }
}
